$(function() {
	$(':input').labelauty();
	setMyActive(4,2,1); //设置激活页
});

// 号码变动时的操作 修改样式
function changemobileExt1(obj) {
	$("#originalprice").empty();
	$("#disprice").empty();
	$("#datapkgids").empty();
	var searchStatus = '查询中请稍后';
	var mobilenumber = $("#mobilenumber").val();
	platform_verify.onblurVali(obj);
	var length = mobilenumber.length;
	$("#disprice").val("");

	var isNumV1Flag = isNumberV1(mobilenumber);
	if (!isNumV1Flag) {
		$("#phoneMessage").html('手机号格式不正确');
	}

	if (length == 11 || length == 13 && isNumV1Flag) {
		$("#phoneMessage").html(searchStatus);
		var dataType = $("input[name='dataType']:checked").val();
		$.ajax({
			type : "get",
			url : basePath + 'sectionAndDataPkgGet',
			data : {
				"phone" : mobilenumber,
				"dataType" : dataType
			},
			dataType : 'json',
			success : function(dt) {
				if (dt != "" && dt != null) {
					$("#provinceCode").empty();
					$("#providerId").empty();
					$("#providerId").val(dt.provider_id);
					$("#provinceCode").val(dt.province_code);
					$("#phoneMessage").html(dt.province_code + "-" + dt.city_code+"-"+dt.providerName);
					$("#terminalName").val(dt.agentName);
					var datapkgids = $("#datapkgids");
					$("#datapkgids").empty();
					$.each(dt.dataPkgMessage, function(index,val) {
					     var li="<li>"+"<input type='radio' " +
					     		"name='datapkgs' onclick='changeDataPkgExt(this);' pkgId="+val.id+" price="+val.price+""+
					     		" value="+val.value+" data-labelauty='"+val.value+"M'/>"+"</li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					     datapkgids.append(li);
					    });	
				} else {
					$("#phoneMessage").html('未知');
				}
				$('input[name=datapkgs]').labelauty();

			},
			error:function(data){
				swal({
 			        title: "系统异常",
 			        type: "success",
 			        confirmButtonText: "ok"
 				});
 			},
		});
	}
	if (length == 0) {
		$("#disprice").val('');
		$("#terminalName").val('');
		$("#phoneMessage").html('');
	}
}

function changeDataPkgExt(obj) {
	$("#originalprice").val('');
	$("#disprice").val('');
	var pkgId= $(obj).attr("pkgId");
	var price= $(obj).attr("price");
	var providerId=$("#providerId").val();
	var dataType = $("input[name='dataType']:checked").val();
	var provinceCode=$("#provinceCode").val();
//	if(dataType=="1"){
//		provinceCode=$("#provinceCode").val();
//	}else{
//		provinceCode="全国";
//	}
	$.ajax({
		type : "get",
		url : basePath + 'agentDataDiscountGet',
		data : {
			"dataPkgId" : pkgId,
			"providerId" : providerId,
			"provinceCode":provinceCode,
			"price":price
		},
		dataType : "json",
		success:function(dt){
			if (dt != "0") {
				$("#originalprice").val(price);
				$("#disprice").val(dt);
			}else{
				$("#originalprice").val(price);
				$("#disprice").val('未查询到折扣');
			}
		}	
	});
		
}

function isNumberV1(str) {
	var myNumber = /^[0-9]+$/;
	return myNumber.test(str);
}


function submitOrder(){
	var spec = $("input[name='datapkgs']:checked").val();
	var terminalName = $("#terminalName").val();
	var phoneNo = $("#mobilenumber").val();
	var orderType = "1";
	var type = $("input[name='dataType']:checked").val();
	var dataType;
	if(type=='2'){
		dataType='2';
	}else{
		dataType='1';
	}
	var type = "1";
	$.ajax({
		type : "get",
		url : basePath + 'order/webSubmit',
		data : {
			"custName" : terminalName,
			"phone" : phoneNo,
			"type" : type,
			"spec" : spec,
			"bizType" : orderType,
			"roamType" : dataType
		},
		success : function(dt) {
			swal({
		        title:dt.message,
		        type: "success",
		        confirmButtonText: "ok"
			},
			function(isConfirm){
				  if (isConfirm) {
					  location.reload();
				  }
			});
		},
		error:function(data){
			swal({
			        title: "系统异常",
			        type: "success",
			        confirmButtonText: "ok"
				});
			},
			dataType : 'json'
	});
}